# Before `make install' is performed this script should be runnable with
# `make test'. After `make install' it should work as `perl test.t'

#########################

# change 'tests => 1' to 'tests => last_test_to_print';

use Test::More tests => 18;
BEGIN { use_ok('WWW::NikePlus') }

#########################

# Insert your test code below, the Test::More module is use()ed here so read
# its man page ( perldoc Test::More ) for help writing this test script.

use Net::Netrc;

my $mach = Net::Netrc->lookup('nikeplus');

my $np = WWW::NikePlus->new(
  login    => $mach->login(),
  password => $mach->password(),
);

is(ref($np), 'WWW::NikePlus', 'Login Successful');

my @challenges = $np->get_challenge_list(active => 1);
my $test = 0;
foreach my $ch (@challenges) {
  $test++ if($ch->isActive());
}
is($test, scalar(@challenges), 'Active Challenges');

@challenges = $np->get_challenge_list(active => 0);
$test = 0;
foreach my $ch (@challenges) {
  $test++ if(!$ch->isActive());
}
is($test, scalar(@challenges), 'Not Active Challenges');

@challenges = $np->get_challenge_list(group => 1);
$test = 0;
foreach my $ch (@challenges) {
  $test++ if($ch->isTeam());
}
is($test, scalar(@challenges), 'Team Challenges');

@challenges = $np->get_challenge_list(group => 0);
$test = 0;
foreach my $ch (@challenges) {
  $test++ if(!$ch->isTeam());
}
is($test, scalar(@challenges), 'Not Team Challenges');

my ($chal) = $np->get_challenge_list(id => '1545324252');

ok(!$chal->isActive(), 'Active');
is(
  $chal->getDescription(), qq{Feel the Olympic Spirit!
Be part of the Olympic Games and run for the Honor of your country!},
  'Description'
);
is($chal->getName(), 'Winter Olympics Vancouver 2010', 'Challenge Name');
is($chal->getID(),   '1545324252',                     'Challenge ID');
is($chal->isTeam(),  1,                                'Team');

is($chal->getStartTime(),   '2010-02-11T23:00:00+00:00', 'Start Time');
is($chal->getEndTime(),     '2010-02-28T22:59:23+00:00', 'End Time');
is($chal->getMemberCount(), 139,                         'Member Count');

is($chal->getRank(),     106, 'Rank');
is($chal->getTeamRank(), 1,   'Team Rank');
ok($chal->getTeams(), 'Teams');
ok($chal->getTeam(),  'Challenge Team');

